;;;
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright:  10-19-1999
;;;	   Edited:  10-19-1999
(DEFUN C:SHTGEN ( / );CURENT CURPLINE PLPTLST SBSSLEN SHBNDSS SHTNOINT SHTNOPFX SHTNOSTR SSCOUNT VPBNDLST
  (vl-load-com)
  (princ "\nNote: Polylines (not LWPoly) must have first segment left to right across bottom of desired view. ")
  (PRINC "\nSelect polylines on layer *SBND* to generate sheets from: ")
  (SETQ shbndss (SSGET '((0 . "POLYLINE")(8 . "*SBND*"))))
  (SETQ sbsslen (SSLENGTH shbndss)
        sscount 0
        plptlst nil
        vpbndlst nil
        shtnopfx (Ustr 1 "Sheet number prefix" (if shtnopfx shtnopfx "C-") nil)
        shtnoint (Uint 1 "" "Starting sheet sequence number" (if shtnoint shtnoint 1))
        shtnostr "001"
  )
  (SETQ dwgnmpfx (Ustr 1 "New Drawing Name prefix? (names will become this prefix followed by three digits)" (IF dwgnmpfx dwgnmpfx "CWMPL") nil))
  (while (< sscount sbsslen)
    (setq curpline (entget (ssname shbndss sscount)))
    (setq curent (entget(entnext (cdr(assoc -1 curpline)))))
    (while (/= (cdr(assoc 0 curent))"SEQEND")
      (if plptlst
        (if (member (cdr(assoc 10 curent)) plptlst)
          nil
          (setq plptlst (append plptlst (list(cdr(assoc 10 curent)))))
        )
        (setq plptlst (append (list(cdr(assoc 10 curent)))))
      )
      (setq curent (entget(entnext (cdr(assoc -1 curent)))))
    )
    (if vpbndlst
      (setq vpbndlst (append vpbndlst (list(cons sscount (list(cons(strcat dwgnmpfx shtnostr ".DWG")(cons(strcat shtnopfx (itoa shtnoint)) plptlst)))))))
      (setq vpbndlst (list(cons sscount (list(cons(strcat dwgnmpfx shtnostr ".DWG")(cons(strcat shtnopfx (itoa shtnoint)) plptlst))))))
    )
    (setq sscount (1+ sscount)
          plptlst nil
          shtnoint (1+ shtnoint)
          shtnostr (cond
                     ((< shtnoint 10)(strcat "00" (itoa shtnoint)))
                     ((< shtnoint 100)(strcat "0" (itoa shtnoint)))
                     ((>= shtnoint 100)(itoa shtnoint))
                   )
    )
  )
  (if attupd nil (load"attupd"))
  (command ".zoom" "1/40xp")
  (command ".erase" shbndss "")
  (vl-load-com)
  (foreach n vpbndlst
    (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-true)
;;;    (command ".mspace")
    (if (not(equal(angle(nth 2(cadr n))(nth 3(cadr n)))0 0.05))
      (command ".dview" "" "tw" (- 360.0(* 90.0(/(angle(nth 2(cadr n))(nth 3(cadr n)))PI))) "")
    )
    (command ".zoom" "w" (nth 5(cadr n))(nth 3(cadr n)))
    (vla-put-MSpace (vla-get-Activedocument (vlax-get-Acad-Object)) :vlax-false)
;;;    (command ".pspace")
    (attupd "CORPTTBAT" "sht_no." (nth 1(cadr n)))
    (command ".saveas" "r14" (strcat(getvar"dwgprefix")(nth 0(cadr n))))
;;;    (c:qsave)
  )
)
  